#ifndef CONNECTION_H
#define CONNECTION_H

#include <QObject>
#include <QLocalSocket>
#include <QSocketNotifier>
#include <QProcess>

class Connection : public QObject
{
    Q_OBJECT
public:
    explicit Connection(quint32 uid, int fd[2], QObject *parent = nullptr);
    ~Connection();

signals:
    void messageReceived(QString msg);
    void disconnected();

public slots:
    void writeMessage(QString msg);
    void writeBuffer(const QByteArray &buffer);

private slots:
    void onSocketReadyRead();
    void onChildFinished(int exitCode, QProcess::ExitStatus status);

private:
    QSocketNotifier *m_localSocketNotifier;
    QLocalSocket *m_localSocket;

    QProcess *m_child;
};

#endif // CONNECTION_H
